/**
 * Created by Lenovo on 2017/8/8.
 */
var intDiff = parseInt(60);//倒计时总秒数量
function timer(intDiff){
    window.setInterval(function(){
        var day=0,
            hour=0,
            minute=0,
            second=0;//时间默认值
        if(intDiff > 0){
            day = Math.floor(intDiff / (60 * 60 * 24));
            hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
            minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
            second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
        }
        if (minute <= 9) minute = '0' + minute;
        if (second <= 9) second = '0' + second;
        $('#day_show').html(day+"天");
        $('#hour_show').html('<s id="h"></s>'+hour+'时');
        $('#minute_show').html('<s></s>'+minute+'分');
        $('#second_show').html('<s></s>'+second+'秒');
        intDiff--;
    }, 1000);
}
$(function(){
    timer(intDiff);

    var sub = startTimeStr.split(" ");
    var before = sub[0].split("-");
    var after = sub[1].split(":");
    var startTime = new Date();
    startTime.setFullYear(before[0]);
    startTime.setMonth(before[1]-1);
    startTime.setDate(before[2]);
    startTime.setHours(after[0]);
    startTime.setMinutes(after[1]);
    startTime.setSeconds(after[2]);
    var now = new Date();
    var long = now - startTime;


    var year = parseInt(Math.abs(now.getFullYear() - startTime.getFullYear()));
    var month = parseInt(Math.abs(year * 12 + now.getMonth() - startTime.getMonth()))
    var days = parseInt(Math.abs(long / 1000 / 60 / 60 / 24));
    var hours = parseInt(Math.abs(long / 1000 / 60 / 60));
    var minute = parseInt(Math.abs(long / 1000 / 60 / 60));
    var seconds = parseInt(Math.abs(long / 1000));


    myTimer(seconds,year,month);


});
var startTimeStr = "2016-07-18 16:38:00"

function myTimer(intDiff,year,month){

    window.setInterval(function(){
        var day=0,
            hour=0,
            minute=0,
            second=0;//时间默认值
        if(intDiff > 0){
            day = Math.floor(intDiff / (60 * 60 * 24));
            hour = Math.floor(intDiff / (60 * 60));
            minute = Math.floor(intDiff / 60);
            second = Math.floor(intDiff);
        }
        if (minute <= 9) minute = '0' + minute;
        if (second <= 9) second = '0' + second;
        $('#my_year_show').html(year+"年");
        $('#my_month_show').html(month+"月");
        $('#my_day_show').html(day+"天");
        $('#my_hour_show').html(hour+'时');
        $('#my_minute_show').html(minute+'分');
        $('#my_second_show').html(second+'秒');
        intDiff++;
    }, 1000);
}